package com.hrms.controller;

import com.hrms.domain.Department;
import com.hrms.domain.web.TableDataInfo;
import com.hrms.domain.web.AjaxResult;
import com.hrms.service.IDepartmentService;
import com.hrms.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 部门管理Controller
 * 
 * @author 老詹
 * @date 2024-11-15
 */
@RestController
@RequestMapping("/admin/department")
public class DepartmentController extends BaseController
{
    @Autowired
    private IDepartmentService departmentService;

    /**
     * 查询部门列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Department department)
    {
        List<Department> list = departmentService.selectDepartmentList(department);
        return getDataTable(list);
    }

    /**
     * 获取部门详细信息
     */
    @GetMapping(value = "/{deptNo}")
    public AjaxResult getInfo(@PathVariable("deptNo") Long deptNo)
    {
        return success(departmentService.selectDepartmentByDeptNo(deptNo));
    }

    /**
     * 新增部门
     */
    @PostMapping
    public AjaxResult add(@RequestBody Department department)
    {
        department.setCreateTime(DateUtils.getNowDate());
        department.setModifyTime(DateUtils.getNowDate());

        return toAjax(departmentService.insertDepartment(department));
    }

    /**
     * 修改部门
     */
    @PutMapping
    public AjaxResult edit(@RequestBody Department department)
    {
        return toAjax(departmentService.updateDepartment(department));
    }

    /**
     * 删除部门
     */
	@DeleteMapping("/{deptNos}")
    public AjaxResult remove(@PathVariable Long[] deptNos)
    {
        return toAjax(departmentService.deleteDepartmentByDeptNos(deptNos));
    }
}
